import logging
from redis import StrictRedis


class Config(object):
    """工程配置信息"""
    DEBUG = False

    SQLALCHEMY_DATABASE_URI = "mysql://root:mysql@127.0.0.1:3306/news"
    SQLALCHEMY_TRACK_MODIFICATIONS = False

    # redis配置
    REDIS_HOST = "127.0.0.1"
    REDIS_PORT = 6379
    REDIS_DATA_DB = 0
    REDIS_SESSION_DB = 1

    # 设置密钥，可以通过base64.b64encode(os.urandom(48))来生成一个指定长度的随机字符串
    SECRET_KEY = "LAKDSHFKKljek*(^()(_(*(^^%U^%UHKUO("

    # flask_session 的配置信息
    SESSION_TYPE = "redis"  # 指定session保存到redis中
    SESSION_USE_SINGER = True  # 让cookie中的session_id被加密签名处理
    SESSION_REDIS = StrictRedis(host=REDIS_HOST, port=REDIS_PORT, db=REDIS_DATA_DB)
    PERMANENT_SESSION_LIFETIME = 86400  # session的有效期，单位是秒

    # 日志记录等级
    LOG_LEVEL = logging.ERROR


class DevelopementConfig(Config):
    """开发模式下的配置"""
    DEBUG = True
    LOG_LEVEL = logging.DEBUG


class ProductionConfig(Config):
    """生产模式下的配置"""
    pass


config = {
    "development": DevelopementConfig,
    "production": ProductionConfig
}